package com.common.UITags;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class ButtonsTag extends TagSupport{
	private static final long serialVersionUID = 1L;
	
	JspWriter out;
	StringBuffer sBF = new StringBuffer();
	
	private String closebutton="true";//是否显示关闭按钮
	private String closebuttoncolor = "info";
	
	@Override
	public int doStartTag() throws JspException {
		try{
			out = pageContext.getOut();
			sBF.setLength(0);
			sBF.append(" <td style=\"text-align: right;\"> ");
			out.print(sBF.toString());
		}catch (IOException e) {
			throw new JspException("标签往前台写数据时异常");
		}catch(Exception e){
			throw new JspException("其他异常");
		}
		return EVAL_BODY_INCLUDE;
	}

	@Override
	public int doEndTag() throws JspException {
		try{
		sBF.setLength(0);
		if(!(closebutton==null||"".equals(closebutton))&&"true".equals(closebutton)){
			sBF.append(" <a class=\"easyui-linkbutton ");
			if("info".equals(closebuttoncolor)){
				sBF.append("button-info");
			}else if("primary".equals(closebuttoncolor)){
				sBF.append("button-default");
			}else if("success".equals(closebuttoncolor)){
				sBF.append("button-success");
			}else if("warning".equals(closebuttoncolor)){
				sBF.append("button-warning");
			}else if("danger".equals(closebuttoncolor)){
				sBF.append("button-danger");
			}else if("inverse".equals(closebuttoncolor)){
				sBF.append("button-inverse");
			}else{
				sBF.append(closebuttoncolor);
			}
			sBF.append("\"");
			sBF.append(" onclick=\"closeCurrentTab()\" ");
			sBF.append(">");
			sBF.append("关闭");//按钮上的文本
			sBF.append("</a>");
		}
		sBF.append(" </td> ");
		out.print(sBF.toString());
		}catch (IOException e) {
			throw new JspException("标签往前台写数据时异常");
		}catch(Exception e){
			throw new JspException("其他异常");
		}
		return EVAL_PAGE;
	}

	//get and set方法
	public String getClosebutton() {
		return closebutton;
	}

	public void setClosebutton(String closebutton) {
		this.closebutton = closebutton;
	}

	public String getClosebuttoncolor() {
		return closebuttoncolor;
	}

	public void setClosebuttoncolor(String closebuttoncolor) {
		this.closebuttoncolor = closebuttoncolor;
	}
	
	
}
